<html>
<head><meta charset="utf-8"><title>what is rust-call · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/what.20is.20rust-call.html">what is rust-call</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="200288752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/what%20is%20rust-call/near/200288752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/what.20is.20rust-call.html#200288752">(Jun 09 2020 at 20:53)</a>:</h4>
<p>For those who are curious, rust-call is our hack to deal with the lack of variadic generics. The built-in fn traits have a single argument type <code>A</code>:</p>
<div class="codehilite"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="nb">Fn</span><span class="o">&lt;</span><span class="n">A</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">type</span> <span class="nc">Output</span><span class="p">;</span><span class="w"> </span><span class="k">fn</span> <span class="nf">call</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">args</span>: <span class="nc">A</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span>::<span class="n">Output</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>this argument is always a tuple. The "rust-call" ABI says "expect a function with a tuple of arguments and flatten them".</p>



<a name="200288846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/what%20is%20rust-call/near/200288846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Areredify <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/what.20is.20rust-call.html#200288846">(Jun 09 2020 at 20:53)</a>:</h4>
<p>A thing of beauty</p>



<a name="200288969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/what%20is%20rust-call/near/200288969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/what.20is.20rust-call.html#200288969">(Jun 09 2020 at 20:54)</a>:</h4>
<p>The hope is that eventually we will have variadic generics -- the <code>Fn</code> traits still can't be implemented by hand, so as to leave room for this</p>



<a name="200289025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/what%20is%20rust-call/near/200289025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/what.20is.20rust-call.html#200289025">(Jun 09 2020 at 20:54)</a>:</h4>
<p>I don't think you can even write <code>T: Fn&lt;X&gt;</code> by hand, you have to use the <code>Fn(...)</code> notation, which forces a tuple</p>



<a name="200289043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/what%20is%20rust-call/near/200289043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/what.20is.20rust-call.html#200289043">(Jun 09 2020 at 20:54)</a>:</h4>
<p>this is sometimes annoying</p>



<a name="200289320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/what%20is%20rust-call/near/200289320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mental <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/what.20is.20rust-call.html#200289320">(Jun 09 2020 at 20:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/144729-wg-traits/topic/what.20is.20rust-call/near/200288969">said</a>:</p>
<blockquote>
<p>The hope is that eventually we will have variadic generics -- the <code>Fn</code> traits still can't be implemented by hand, so as to leave room for this</p>
</blockquote>
<p>Do you know why they can't be implemented manually? (or is it more look away magic)</p>



<a name="200289344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/what%20is%20rust-call/near/200289344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/what.20is.20rust-call.html#200289344">(Jun 09 2020 at 20:57)</a>:</h4>
<p>There is special code in the compiler to prevent it</p>



<a name="200289359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/what%20is%20rust-call/near/200289359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/what.20is.20rust-call.html#200289359">(Jun 09 2020 at 20:57)</a>:</h4>
<p>The methods are unstable.</p>



<a name="200289388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/what%20is%20rust-call/near/200289388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/what.20is.20rust-call.html#200289388">(Jun 09 2020 at 20:58)</a>:</h4>
<p>This is so that you can't make impls that violate the rust-call ABI expectations</p>



<a name="200289426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/what%20is%20rust-call/near/200289426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/what.20is.20rust-call.html#200289426">(Jun 09 2020 at 20:58)</a>:</h4>
<p>and so you don't have stable code that references the rust-call ABI</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>